//
//  HttpUserManager.m
//  Cat
//
//  Created by lushitong on 2018/12/1.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "HttpUserManager.h"
#import "HttpUserPtl.h"
#import "HttpUserParser.h"
#import "FMDBUser.h"
#import "MemberModel.h"
#import "EarnModel.h"
#import "RelationModel.h"
#import "BalancelModel.h"
#import "BrokModel.h"
#import "InviteModel.h"

@implementation HttpUserManager

+ (void)sendVerifyCodeWithMobile:(NSString *)phoneString withSuccuss:(FLSuccess)success failure:(FLFailure)failure {
	[HttpUserPtl sendVerifyCodeWithMobile:phoneString withSuccuss:success failure:failure];
}

+ (void)loginWithPhoneNumber:(NSString *)phoneString andVerifyCode:(nonnull NSString *)code inviteCode:(nonnull NSString *)inviteNumber withSuccuss:(nonnull void (^)(NSString * _Nonnull))success failure:(nonnull FLFailure)failure {
	[HttpUserPtl loginWithPhoneNumber:phoneString andVerifyCode:code inviteCode:inviteNumber withSuccuss:^(NSDictionary *dict) {
		if (dict) {
			UDPhone = phoneString;
			success(dict[@"token"]);
		}
	} failure:failure];
}

+ (void)getUserInfsuccess:(void (^)(FMDBUser * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl getUserIfnowithSuccuss:^(NSDictionary * _Nonnull dict) {
		if (dict) {
			FMDBUser *user = [HttpUserParser parseUserData:dict];
			[user bg_saveOrUpdate];
			success(user);
		}
	} failure:failure];
}

+  (void)getMemberInfoSucces:(void (^)(MemberModel * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl getMemberInfoSucces:^(NSDictionary * _Nonnull dict) {
		if (dict) {
			MemberModel *model = [HttpUserParser parseMemberData:dict];
			success(model);
		}
	} failure:failure];
}

+ (void)senFeedBackWithContext:(NSString *)feedBack withSuccuss:(FLSuccess)success failure:(FLFailure)failure {
	[HttpUserPtl senFeedBackWithContext:feedBack withSuccuss:success failure:failure];
}

+ (void)getEarnInfo:(void (^)(EarnModel * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl getEarnInfowithSuccuss:^(NSDictionary * _Nonnull dict) {
		if (dict) {
			EarnModel *model = [EarnModel yy_modelWithDictionary:dict];
			if (success) {
				success(model);
			}
		}
	} failure:failure];
}

+ (void)getFansCountInfo:(void (^)(NSNumber *, NSString * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl getFansCountInfo:^(NSDictionary * _Nonnull dict) {
		if (success) {
			success(dict[@"total"],dict[@"amount"]);
		}
	} failure:failure];
}

+ (void)getElationListWihIndex:(NSNumber *)index andType:(NSString *)type andSuccessInfo:(void (^)(RelationModel * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl getElationListWihIndex:index andType:type withSuccuss:^(NSDictionary * _Nonnull dict) {
		if (success) {
			RelationModel *mode = [RelationModel yy_modelWithDictionary:dict];
			if (success) {
				success(mode);
			}
		}
	} failure:failure];
}

+ (void)userUpdateInfo:(NSString *)avatar
		  withNickName:(NSString *)nickString
		   withSuccuss:(FLSuccess)success
			   failure:(FLFailure)failure {
	[HttpUserPtl userUpdateInfo:avatar withNickName:nickString withSuccuss:success failure:failure];
}

+ (void)upLoadFile:(UIImage *)avatarImage andSuccessInfo:(void (^)(NSString * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl upLoadFile:avatarImage withSuccuss:^(NSDictionary * _Nonnull dict) {
		if (success) {
			success(dict[@"url"]);
		}
	} failure:failure];
}


+ (void)fundoutPutnSuccessInfo:(void(^)(NSString *url))success
					   failure:(FLFailure)failure {
	[HttpUserPtl fundoutPutnSuccessInfowithSuccuss:^(NSDictionary *dict) {
		
	} failure:failure];
}

+ (void)balanceListIndex:(NSNumber *)index success:(void (^)(NSArray * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl balanceListIndex:index success:^(NSDictionary *dict) {
		NSArray *array = [NSArray yy_modelArrayWithClass:[BalancelModel class] json:dict];
		if (success) {
			success(array);
		}
	} failure:failure];
}

+ (void)brokListIndex:(NSNumber *)index type:(NSString *)type success:(void(^)(NSArray *brokArray))success failure:(FLFailure)failure {
	[HttpUserPtl brokListIndex:index type:type success:^(NSDictionary *dict) {
		NSArray *array = [NSArray yy_modelArrayWithClass:[BrokModel class] json:dict];
		if (success) {
			success(array);
		}
	} failure:failure];
}

+ (void)balanceGetSuccess:(void (^)(NSString * _Nonnull, NSString * _Nonnull, NSNumber * _Nonnull))success failure:(FLFailure)failure {
	[HttpUserPtl balanceGetSuccess:^(NSDictionary *dict) {
		if (success) {
			success(dict[@"alipayNo"],dict[@"realName"],@([dict[@"balance"] integerValue]));
		}
	} failure:failure];
}

+ (void)balanceUpdatePayName:(NSString *)payName realName:(NSString *)realName phoneNumber:(NSString *)phoneNumber verCode:(NSString *)code withSuccuss:(FLSuccess)success failure:(FLFailure)failure {
	[HttpUserPtl balanceUpdatePayName:payName realName:realName phoneNumber:phoneNumber verCode:code withSuccuss:success failure:failure];
}

+ (void)balanceamount:(NSNumber *)amount
           PutSuccuss:(FLSuccess)success
				  failure:(FLFailure)failure {
    [HttpUserPtl balanceAmount:amount putSuccess:success failure:failure];
}

+ (void)getInviteStausByPhone:(NSString *)phone
                      success:(void (^)(BOOL))success
                      failure:(FLFailure)failure {
    [HttpUserPtl getInviteStausByPhone:phone success:^(NSDictionary *dict) {
        if (success) {
            success([dict[@"hasInviteCode"] boolValue]);
        }
    } failure:failure];
}

+ (void)getInviteListWithIndex:(NSNumber *)index success:(void (^)(NSArray * _Nonnull))success failure:(FLFailure)failure {
    [HttpUserPtl getInviteListWithIndex:index success:^(NSDictionary *dict) {
        NSArray *array = [NSArray yy_modelArrayWithClass:[InviteModel class] json:dict];
        if (success) {
            success(array);
        }
    } failure:failure];
}

@end
